package com.itsm.example.audit.controller;

import com.itsm.example.audit.pojo.context.AuditContext;
import com.itsm.example.audit.pojo.dto.Result;
import com.itsm.example.audit.pojo.event.AuditEvent;
import com.itsm.example.audit.pojo.param.AuditParam;
import com.itsm.example.audit.service.AuditService;
import com.itsm.example.statemachine.bo.ItsmEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author benym
 * @date 2023/7/12 15:50
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Autowired
    private AuditService auditService;

    @PostMapping("/audit")
    public Result audit(@RequestBody @Validated AuditContext auditContext){
//        AuditContext auditContext = AuditContext.builder().build();
//        BeanUtils.copyProperties(auditParam, auditContext);
        return Result.success( auditService.audit(auditContext));
    }
    @GetMapping("/getNextStep")
    public Result getNextStep(long id){
        List<ItsmEvent> eventList = auditService.getNextStep(AuditContext.builder().id(id).build());
        log.info("getNextStep:{}", eventList);
        return Result.success(eventList.toString());
    }

    @GetMapping("/uml")
    public String uml(long id){
        return auditService.uml(AuditContext.builder().id(id).build());
    }
}
